home comics writing pictures archive about

RecurringExpenseItem.cs

Language: C#
Last Modified: 2020-06-27 1:58:31 PM UTC
File Size: 3506 bytes
http://www.penguinstew.ca/example/dataviewer/Model/RecurringExpenseItem.cs
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
namespace Budgeter.Model
{
[Table(Name = "RecurringPaymentItems")]
public class RecurringPaymentItem: IRefreshableTable
{
#region Constructor
public RecurringPaymentItem()
{
Children = new EntitySet<RecurringPaymentItem>();
}
#endregion
#region Columns
/// <summary>
/// Unique ID
/// </summary>
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int RecurringPaymentItemId { get; set; }
/// <summary>
/// The key of the related recurring Payment
/// </summary>
[Column]
public int RecurringPaymentId { get; set; }
/// <summary>
/// The key of the parent item (null if root)
/// </summary>
[Column]
public int? ParentId { get; set; }
/// <summary>
/// The item name
/// </summary>
[Column(DbType = "nvarchar(150) NOT NULL")]
public string Name { get; set; }
/// <summary>
/// The item amount
/// </summary>
[Column]
public decimal Amount { get; set; }
#endregion
#region Entities
private EntityRef<RecurringPayment> m_recurringPayment;
/// <summary>
/// Reference to the related recurring Payment
/// </summary>
[Association(Storage = "m_recurringPayment", ThisKey = "RecurringPaymentId", IsForeignKey = true)]
public RecurringPayment RecurringPayment
{
get
{
return m_recurringPayment.Entity;
}
set
{
m_recurringPayment.Entity = value;
}
}
private EntityRef<RecurringPaymentItem> m_parent;
/// <summary>
/// Reference to the item's parent
/// </summary>
[Association(Storage = "m_parent", ThisKey = "ParentId", IsForeignKey = true)]
public RecurringPaymentItem Parent
{
get
{
return m_parent.Entity;
}
set
{
m_parent.Entity = value;
}
}
private EntitySet<RecurringPaymentItem> m_children;
/// <summary>
/// Reference to the item's children
/// </summary>
[Association(Storage = "m_children", OtherKey = "ParentId")]
public EntitySet<RecurringPaymentItem> Children
{
get
{
return m_children;
}
set
{
m_children = value;
}
}
#endregion
#region IRefreshableTable
public void RefreshEntitySets(Connection.BudgeterDataContext connection)
{
Children.Clear();
Children.AddRange(connection.RecurringPaymentItems.Where(i => i.ParentId == RecurringPaymentItemId));
}
#endregion
#region Override
public override string ToString()
{
if (Children.Count == 0)
{
return string.Format("{0} {1}", Name, Amount.ToString("C"));
}
else
{
return Name;
}
}
#endregion
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135